Arduino Interrupts: Speed up your Arduino to be responsive to events by Claus Kühnel

Arduino Interrupts: Speed up your Arduino to be responsive to events by Claus Kühnel

Author:Claus Kühnel [Kühnel, Claus]
Language: eng
Format: azw3, epub, pdf
Publisher: Skript Verlag Kühnel
Published: 2017-05-10T04:00:00+00:00


Table 7 Configuration of output OC1A respectively OC1B

Table 8 Selection of Prescaler or external clock

Table 9 Setting the operating mode – excerpt

Timer2 Program Sample

In the following program example Timer2 should generate a clock of 10 ms.

From Table 3, a prescaler of 1024 can be obtained for Timer2 for a maximum timer period of approx. 16 ms. After 156 clocks the time of 10 ms is reached.

If you run Timer2 in the CTC mode and load the Output Compare Register with a value of 0x9C (= 156), an interrupt request is obtained after 10 ms.

Listing 5 shows the source code of the program example msecTimer.ino. In the interrupt service routine, the variablecount is counted up and register OCR2A is reloaded. The variable count is evaluated in the main loop.

In the setup routine, the initialization of the registers of Timer2 is performed according to the previously described specifications.

In the main loop, the variablecount is requested. If this value reaches 50 after 500 ms, a character is output at the terminal and the LED is toggled. The flashing of LED with a rate of one second (2 x 500 ms) serves as an indicator of the expected function. Figure 12 shows the terminal output of the program example msecTimer.ino.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.